package com.leetcode.hash.demo1;

/**
 * @Author Zan
 * @Create 2024/5/16 8:35
 * @ClassName: Test
 * @Description : https://leetcode.cn/problems/valid-anagram/  有效的字母异位词
 */
public class Test {
    public static void main(String[] args) {

    }
}

class Solution {
    public boolean isAnagram(String s, String t) {
        // 先将s存到数组当中，根据ASCII码进行存储，然后根据t进行-1操作，最后检查是否全为0
        int[] arr = new int[26];
        for (int i = 0; i < s.length(); i++) {
            int index = s.charAt(i) - 'a';
            arr[index]++;
        }

        for (int i = 0; i < t.length(); i++) {
            int index = t.charAt(i) - 'a';
            arr[index]--;
        }

        for (int i = 0; i < arr.length; i++) {
            if (arr[i] != 0) {
                return false;
            }
        }
        return true;
    }
}
